<?php
namespace app\home\controller;
use think\Db;
use think\captcha\Captcha;
use think\Loader;
class Checkout extends \think\Controller{
    public function checkout(){
        $ret=db('shoppingcart')->alias('a')->join('admin_addshop b',' a.shop_id=b.id ')
        ->field('b.*')->select();

        $data=array();
        foreach($ret as $val){
            $img=json_decode($val['img'],true);
            if($img!=NULL){
                $val['img']=$img;
            }
            $data[]=$val;
        }
        $this->assign('ret',$data);

        return $this->fetch('checkout');//继承基类的控制器 
    }
    public function index(){
        $data=input('param.','','htmlspecialchars');
        $province=input('param.province','','htmlspecialchars');
        $city=input('param.city','','htmlspecialchars');
        $district=input('param.district','','htmlspecialchars');
        $address=input('param.address','','htmlspecialchars');
        $postalCode=input('param.postalCode','','htmlspecialchars');
        $realName=input('param.realName','','htmlspecialchars');
        $phoneNum=input('param.phoneNum','','htmlspecialchars');
        $tellNum=input('param.tellNum','','htmlspecialchars');
        $logistics=input('param.logistics','','htmlspecialchars');
        $data['out_trade_no']=date('Ymdhim',time()).rand(1000,9999);
        $data['subject']=$data['realName'].'的订单';
        // $data['total_amount']=$data[''];
        $data['add_time']=time();

       
        $ret=db('order')->insertGetId($data);   
            
        if($ret>0){
            session('order_id',$ret);
            
            $this->success('提交成功!','home/zhifubao/zhifubao');
        }else{
            $this->error('提交失败');
        }
    }
    
}